#include <iostream>
#include <math.h>
using namespace std;
const int inf=0x7fffffff;


struct book{
	int value,weight;
};


int main(){
	int n,ans;
	cin>>n;
	book a[n];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i].value>>a[i].weight;
		sum += a[i].value;
	}
	int dp[sum+1];
	for(int i=1;i<=sum;i++)
		dp[i] = inf;
	dp[0] = 0;
	for(int i=0;i<n;i++)
		for(int j=sum;j>=a[i].value;j--)
			dp[j] = min(dp[j],dp[j-a[i].value]==inf?inf:dp[j-a[i].value]+a[i].weight);
	for(int i=sum;i>=0;i--){
		if(dp[i] <= sum-i){
			ans = sum-i;
			break;
		}
	}
	cout<<ans;
	return 0;
}
